package com.zodiac.alioth.common.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * @author daixulin
 * @version : v1.0
 * @date 2022-08-12 4:37 PM 周五
 */
public class BeanCopyUtil extends BeanUtils {
    public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target, Object o) {
       return copyListProperties(sources, target, null);
    }

    public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target, BeanCopyUtilCallBack<S, T> callback) {
        List<T> list = new ArrayList<>(sources.size());
        for (S source : sources) {
            T t = target.get();
            copyProperties(source, t);
            list.add(t);
            if (callback != null) {
                // 回调
                callback.callBack(source, t);
            }
        }
        return list;
    }
}
